<template>
  <div class="shopCar">
    <div class="goodlist">
       <div class="mui-card" v-for="item of carList" :key="item.id">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <mt-switch v-model="$store.getters.getGoodsSelected[item.id]"
          @change="selectChange(item.id,$store.getters.getGoodsSelected[item.id])"
          ></mt-switch>
          <img src="../../images/time.jpg" alt="">
          <div class="info">
            <h2>我是标题</h2>
            <p>
              <span class="price">¥{{item.price}}</span>
              <num :initcount="$store.getters.getGoodsCount[item.id]" :countId="item.id"></num>
              <a @click.prevent="removeItem(item.id)">删除</a>
            </p>
          </div>
        </div>
      </div>
    </div>
    </div>
    
   
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总计(不含运费)</p>

            <p>已勾选商品<span>{{$store.getters.getGoodsTotal.count}}</span>件，总计<span>¥{{$store.getters.getGoodsTotal.amount}}</span></p>
          </div>
          <mt-button type="danger">去结算</mt-button>
      
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import num from "../sub/num_shopcar.vue";
export default {
  data() {
    return {
      carList:this.$store.state.car
    };
  },
  created(){
    console.log(this.$store.state.car)
  },
  components: {
    num
  },
  methods:{
    removeItem(id){
      console.log(id)
      this.$store.commit('removeCar',id)
    },
    selectChange(id,status){
      this.$store.commit('changeStatus',{
        id,
        select:status
      })
    }
  }
};
</script>

<style lang="scss" scoped>
.shopCar {
  background: #eee;
  overflow: hidden;
  .goodlist{
    .mui-card-content-inner{
      display: flex;
      align-items: center;
      img{
        width: 60px;
        height: 60px;
      }
      .info{
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        h2{
          font-size:13px;
        }
        p{
          .price{
            color: red;
            font-weight: bold
          }
        }
      }
    }
  }
  .jiesuan{
    display: flex;
    justify-content: space-between;
    align-items: center;
    span{
      color: red;
      font-size: 16px;
      font-weight: bold;
    }
  }
}
</style>

